﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BE;
using BLL;

namespace UI
{
    public partial class AlbumPage : System.Web.UI.Page
    {
        
        Album album = null;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string id = Request.QueryString["id"];
				if ( id == null )
				{
					Response.Redirect("MusicPage.aspx");
				}
                album = AlbumManager.getAlbum(int.Parse(id));
                insertImage();
                createAlbumTable();
            }
        }

        private void insertImage()
        {
            Image image = new Image();
            image.ImageUrl = "albumcovers/" + album.Image;
            phImage.Controls.Add(image);
        }

        private void createAlbumTable()
        {
            TableRow tblRow = new TableRow();
            tblAlbum.Controls.Add(tblRow);
            tblRow.Controls.Add(createCell("Artist: "));
            tblRow.Controls.Add(createCell(album.Artist));

            tblRow = new TableRow();
            tblAlbum.Controls.Add(tblRow);
            tblRow.Controls.Add(createCell("Album: "));
            tblRow.Controls.Add(createCell(album.Title));

            tblRow = new TableRow();
            tblAlbum.Controls.Add(tblRow);
            tblRow.Controls.Add(createCell("Genre: "));
            tblRow.Controls.Add(createCell(GenreManager.getGenres(album.Genre)));

            tblRow = new TableRow();
            tblAlbum.Controls.Add(tblRow);
            tblRow.Controls.Add(createCell("Year: "));
            tblRow.Controls.Add(createCell(album.Year.ToString()));
        }

        private TableCell createCell(string text)
        {
            TableCell cell = new TableCell();
            Label lbl = new Label();
            lbl.Text = text;
            cell.Controls.Add(lbl);
            return cell;
        }
    }
}